﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Innova.Microfinanzas.BusinessEntities;

namespace Innova.Microfinanzas.Windows.Common.Views.Common
{
    public partial class CustomerSelectionList : Form
    {
        public CustomerSelectionList()
        {
            InitializeComponent();
        }

        public static Customer ShowSelectedCustomerView(List<Customer> colItems)
        {
            CustomerSelectionList objForm = new CustomerSelectionList();
            objForm.ColCustomers = colItems;
            objForm.ShowDialog();
            return objForm.ObjSelectedCustomer;
        }

        public Customer ObjSelectedCustomer
        {
            get;
            set;
        }

        public List<Customer> ColCustomers
        {
            get
            {
                return (List<Customer>)gridCustomers.DataSource;
            }
            set
            {
                gridCustomers.DataSource = value;
                gridCustomers.DataBind();
            }
        }

        public void SetCustomerSelected()
        {
            if (gridCustomers.ActiveRow != null
                && gridCustomers.ActiveRow.Selected)
            {
                ObjSelectedCustomer = (Customer)gridCustomers.ActiveRow.ListObject;
                Close();
            }
        }

        private void gridCustomers_DoubleClickRow(object sender, Infragistics.Win.UltraWinGrid.DoubleClickRowEventArgs e)
        {
            SetCustomerSelected();
        }

        private void tsSaveButtonToolStrip_Click(object sender, EventArgs e)
        {
            SetCustomerSelected();
        }

        private void tsCancelButtonToolStrip_Click(object sender, EventArgs e)
        {
            ObjSelectedCustomer = null;
            Close();
        }
    }
}
